//
//  NSDictionary+Property.m
//  05-RunTime（字典转模型KVC实现）
//
//  Created by ukongm on 16/9/25.
//  Copyright © 2016年 ukongm. All rights reserved.
//

#import "NSDictionary+Property.h"

@implementation NSDictionary (Property)

//生成属性代码的 = > 根据字典中的所有key
- (void)createProertyCode{
    
    NSMutableString* codes = [NSMutableString new];
    
    [self enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
       
        NSString* code;
        
        if ([obj isKindOfClass:[NSString class]]) {
            code = [NSString stringWithFormat:@"@property(nonatomic,strong)NSString<Optional> * %@;",key];
        } else if ([obj isKindOfClass:NSClassFromString(@"__NSCFBoolean")]){
            code = [NSString stringWithFormat:@"@property(nonatomic,assign)BOOL %@;",key];
        } else if ([obj isKindOfClass:[NSNumber class]]){
            code = [NSString stringWithFormat:@"@property(nonatomic,strong)NSNumber<Optional> * %@;",key];
        } else if ([obj isKindOfClass:[NSArray class]]){
            code = [NSString stringWithFormat:@"@property(nonatomic,strong)NSArray<Optional> * %@;",key];
        } else if ([obj isKindOfClass:[NSDictionary class]]){
            code = [NSString stringWithFormat:@"@property(nonatomic,strong)NSDictionary<Optional> * %@;",key];
        }
        
        [codes appendFormat:@"%@\n",code];
        
    }];
    
    NSLog(@"%@",codes);
    
}

@end
